import 'package:flutter/material.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';
import 'package:get/get.dart';
import 'package:raze/potions/raze_constant.dart';

/// 加载指示器组件，使用 flutter_spinkit 实现加载动画
/// 支持显示和关闭加载状态
class LoaderAura {
  /// 显示加载指示器
  static void unveilProgress() {
    Get.dialog(
      PopScope(
        canPop: false, // 阻止用户通过返回键关闭
        child: Dialog(
          backgroundColor: Colors.transparent,
          elevation: 0,
          child: Container(
            padding: const EdgeInsets.all(20),
            decoration: BoxDecoration(
              color: RazeConstants.white,
              borderRadius: BorderRadius.circular(12),
            ),
            child: Column(
              mainAxisSize: MainAxisSize.min,
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                SpinKitCircle(color: RazeConstants.blue, size: 50.0),
                const SizedBox(height: 20),
                Text(
                  "Loading...",
                  style: TextStyle(color: RazeConstants.black, fontSize: 14),
                ),
              ],
            ),
          ),
        ),
      ),
      barrierDismissible: false, // 点击背景不关闭
    );
  }

  /// 关闭加载指示器
  static void concealProgress() {
    if (Get.isDialogOpen ?? false) {
      Get.back();
    }
  }
}
